home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992…ugust: Hack to the Future / ADC Developer CD (1992-08) (''Hack To The Future'')_iso / Dev.CD 199208.iso / Periodicals / develop / develop 9 code / Tracks / TestDrvr ƒ / drvr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-06  |  3.5 KB  |  169 lines  |  [TEXT/MPS ]

  1. #include "TestDrvr.h"
  2. #include "TracksInfo.h"
  3. #include <Events.h>        /* For keymap definition */
  4. #include <ToolUtils.h>
  5. #include <Errors.h>
  6. #include <Memory.h>>
  7. #include <Resources.h>
  8. #include <Devices.h>
  9. #include <types.h>     // Mac types
  10. #include <Desk.h>    /* for accRun */
  11. #include <Quickdraw.h>
  12.  
  13. #include <Files.h>
  14.  
  15.  
  16. pascal short DrvrEntry(Globals *globals, short csCode, Ptr paramPtr, DCtlPtr dCtl) 
  17. {
  18.  
  19. short result = noErr;
  20.  
  21.     
  22.     switch (csCode)
  23.     {
  24.         
  25.       case kInstallTrace:    
  26.           globals->fTraceProcPtr = ((TraceDataPtr)paramPtr)->TraceProc;
  27.           globals->fTraceArg = ((TraceDataPtr)paramPtr)->TraceGlobals;        
  28.         break;
  29.         
  30.       case kRemoveTrace:
  31.         globals->fTraceProcPtr = nil;
  32.         globals->fTraceArg = nil;
  33.         break;
  34.     
  35.       case accRun:        // Periodic Event
  36.           globals->EventCount++;
  37.         
  38.           if (OPTION_KEY_DOWN())
  39.             HandleOptKeyDown(globals);
  40.         else 
  41.             if (CMD_KEY_DOWN())
  42.                 HandleCmdKeyDown(globals, dCtl);
  43.  
  44.         break;
  45.       default:
  46.           T_STACK(kStackPeekEx);
  47.         T_PSTR(kUnexpectedErr, 0, "\pUnknown csCode");
  48.         
  49.         result = controlErr;        // no such csCode 
  50.         break;
  51.     }
  52.  
  53.     return(result);
  54. }
  55.  
  56. void HandleOptKeyDown(Globals *globals)
  57. {
  58.     /* This will record who called this routine. */
  59.     T_STACK(kStackPeekEx);        /* This will log that 'DrvrEntry' was called by 'TControl'  */
  60.     
  61.     /* Log periodic event count */
  62.     T_PSTRLONG(kOptKeyDown, 0, "\pEventCount = ", (long) globals->EventCount);
  63.     T_PSTR(kOptKeyDown, 1, "\pKeyMap = ");
  64.     T_DATA(kOptKeyDown, 2, theKeyMap, (long)sizeof(KeyMap));
  65.     
  66. }
  67.  
  68. void HandleCmdKeyDown(Globals *globals, DCtlPtr dCtl)
  69. {
  70.     /* This will record who called this routine. */
  71.     T_STACK(kStackPeekEx);
  72.     // How to send formatted data.  The template is defined in Macsbug's "Debugger Prefs"
  73.     // file in resource 'mxwt' "Macsbug 6.2".  
  74.     
  75.     T_TYPE(kCmdKeyDown, 0, dCtl, (long)sizeof(DCtlEntry), (long)"\pDCtlEntry");
  76. }
  77.  
  78.  
  79. OSErr TControl(CntrlParam *ctlPB, DCtlPtr dCtl)
  80.     {
  81.     register OSErr error;
  82.     register short csCode;
  83.     register Ptr paramPtr;    
  84.     register Globals *globals;
  85.         
  86.     // The dCtlStorage field in the DCE entry contains our globals pointer
  87.  
  88.     globals = (Globals *) dCtl->dCtlStorage;
  89.     csCode = ctlPB->csCode;
  90.     
  91.     paramPtr = (Ptr)&(ctlPB->csParam);
  92.  
  93.     error = DrvrEntry(globals, csCode, paramPtr, dCtl);
  94.         
  95.     return(error);
  96.     
  97.     }
  98.  
  99.  
  100. OSErr TOpen(CntrlParam *ctlPB, DCtlPtr dCtl)
  101.     {
  102. #pragma unused (ctlPB)
  103.     register OSErr error;
  104.     register Globals *globals;
  105.  
  106.     // The dCtlStorage field in the DCE entry is used to keep a pointer
  107.     // to the global memory block.  This will be nil on the first Open call.
  108.     
  109.     error = noErr;
  110.     globals = (Globals *) dCtl->dCtlStorage;
  111.     
  112.     if (globals == nil)
  113.         {
  114.         // Allocate global storage as a non-relocatable block on the System Heap...
  115.  
  116.           globals = (Globals *) NewPtrSysClear(sizeof(Globals));
  117.  
  118.         if (globals == nil)
  119.             error = MemError();
  120.         else
  121.             {
  122.                 // Save a pointer to the globals in the DCE:
  123.                 dCtl->dCtlStorage = (Handle) globals;
  124.                 
  125.                 // Init other driver specific globals...
  126.                 globals->EventCount = 0;
  127.                 
  128.             }
  129.         }
  130.  
  131.     return(error);
  132.     
  133.     }
  134.  
  135.  
  136. OSErr TPrime(CntrlParam *ctlPB, DCtlPtr dCtl)
  137.     {
  138. #pragma unused (ctlPB, dCtl)
  139.     return(readErr);
  140.     }
  141.  
  142. OSErr TStatus(CntrlParam *ctlPB, DCtlPtr dCtl) 
  143. {
  144. register OSErr error;
  145. register short csCode;
  146. register Ptr paramPtr;    
  147. register Globals *globals;
  148.         
  149.     // The dCtlStorage field in the DCE entry contains our globals pointer
  150.  
  151.     globals = (Globals *) dCtl->dCtlStorage;
  152.     csCode = ctlPB->csCode;
  153.     
  154.     paramPtr = (Ptr)&(ctlPB->csParam);
  155.  
  156.     error = DrvrEntry(globals, csCode, paramPtr, dCtl);
  157.         
  158.     return(error);
  159.     
  160. }
  161.  
  162.  
  163. OSErr TClose(CntrlParam *ctlPB, DCtlPtr dCtl)
  164. {
  165. #pragma unused (ctlPB,dCtl)
  166.     return(closErr); // Not allowed to close this driver
  167. }
  168.  
  169.